package com.accompany.api.presenter;
import com.accompany.api.bean.OrderMesgBean;
import com.accompany.api.category.OrderCategory;
import com.accompany.base.BaseBean;
import com.accompany.main.ConstantStaticUrl;
import com.accompany.utils.RetrofitUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
 * 信息说明:
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/4/30 17 ：15
 * 项目名称：yuanban
 */
public class OrderPresenter implements OrderCategory.Presenter {
    OrderCategory.View view;
    public OrderPresenter(OrderCategory.View view) {
        this.view = view;
    }
    @Override
    public void getOrderList(int pageNumber, String mToken, long acdId, int orderStatus) {
        RetrofitUtil.getInstance().getmService().get_order_list(mToken, acdId, orderStatus, pageNumber, ConstantStaticUrl.PAGE_NUMBER).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    OrderMesgBean userInfor = gson.fromJson(result, OrderMesgBean.class);
                    view.getOrderList(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
    @Override
    public void getDeleteOrder(String mToken, long orderId) {
        RetrofitUtil.getInstance().getmService().get_delete_order(mToken,orderId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    BaseBean userInfor = gson.fromJson(result, BaseBean.class);
                    view.getDeleteOrder(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
}
